package com.xfp.controller;

import com.xfp.pojo.dto.CancelTaskDto;
import com.xfp.pojo.dto.TaskInfoDto;
import com.xfp.pojo.dto.TaskQueryDto;
import com.xfp.pojo.entity.*;
import com.xfp.pojo.vo.*;
import com.xfp.service.TaskService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/task-service")
@RequiredArgsConstructor
@Slf4j
public class TaskController {

    private final TaskService taskService;

    /**
     * 工单状态统计
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/task/collectReport/{start}/{end}")
    @ApiOperation("工单状态统计")
    public List<CollectReportVo>  collectReport(@PathVariable String start,@PathVariable String end){
        log.info("工单状态统计：{}，{}",start,end);
        return taskService.collectReport(start,end);
    }

    /**
     *获取当时工单汇总信息(人员统计头部信息)
     */
    @GetMapping("/task/taskReportInfo/{start}/{end}")
    @ApiOperation("/获取当时工单汇总信息")
    public List<TaskReportInfoVo> taskReportInfo(@PathVariable String start,@PathVariable String end){
        log.info("获取当时工单汇总信息");
        return taskService.taskReportInfo(start,end);
    }

    /**
     * 工单搜索
     */
    @GetMapping("/task/search")
    @ApiOperation("工单搜索")
    public TaskQueryVo taskSearch(TaskQueryDto dto){
        log.info("工单搜索");
        TaskQueryVo vo = taskService.taskSearch(dto);
        return vo;
    }

    /**
     * 创建工单
     */
    @PostMapping("/task/create")
    @ApiOperation("创建工单")
    public Boolean createTask(@RequestBody TaskInfoDto dto){
        log.info("创建工单");
        taskService.createTask(dto);
        return true;
    }

    /**
     * 工单状态列表
     */
    @GetMapping("/task/allTaskStatus")
    @ApiOperation("工单状态列表")
    public List<TaskStatusType> allTasksStatus(){
        log.info("工单状态列表");
        List<TaskStatusType> list = taskService.allTaskStatus();
        return list;
    }

    /**
     * 获取所有工单类型
     */
    @GetMapping("/taskType/list")
    @ApiOperation("获取所有工单类型")
    public List<TaskType> taskTypeList(TaskQueryDto dto){
        log.info("获取所有工单类型：{}",dto);
        List<TaskType> list = taskService.taskTypeList();
        return list;
    }

    /**
     * 获取工单详情
     */
    @GetMapping("/task/taskInfo/{taskId}")
    @ApiOperation("获取工单详情")
    public TaskInfoVo taskInfo(@PathVariable Long taskId){
        log.info("获取工单类型");
        TaskInfoVo vo = taskService.taskInfo(taskId);
        return vo;
    }

    /**
     * 补货详情
     */
    @GetMapping("/taskDetails/{taskId}")
    @ApiOperation("补货详情")
    public List<TaskDetails> taskDetails(@PathVariable Long taskId, TaskInfoDto dto){
        log.info("补货详情");
        List<TaskDetails> list = taskService.taskDetails(taskId,dto);
        return list;
    }

    /**
     * 获取补货预警值
     */
    @GetMapping("/task/supplyAlertValue")
    @ApiOperation("获取补货预警值")
    public Integer getAlertValue(){
        log.info("获取补货预警值");
        return taskService.getAlertValue();
    }

    /**
     * 设置自动补货工单阈值
     */
    @PostMapping("/task/autoSupplyConfig")
    @ApiOperation("设置自动补货工单阈值")
    public Boolean autoSupplyConfig(@RequestBody AlertValue alertValue){
        log.info("设置自动补货工单阈值");
        taskService.autoSupplyConfig(alertValue);
        return true;
    }

    /**
     * 取消工单
     */
    @PostMapping("/task/cancel/{taskId}")
    @ApiOperation("取消工单")
    public Boolean cancelTask(@PathVariable Integer taskId, @RequestBody CancelTaskDto dto){
        log.info("取消工单");
        taskService.cancelTask(taskId,dto);
        return true;
    }

}
